package com.passport_main.service;

import com.passport_main.dao.mapper.PassportMapper;
import com.passport_main.pojo.entity.MyUserDetails;
import com.passport_main.pojo.vo.UserDetailsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.rmi.server.UID;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    PassportMapper passportMapper;

    @Override
    public UserDetails loadUserByUsername(String uid) throws UsernameNotFoundException {
        long l = Long.parseLong(uid);
        UserDetailsVO userDetails = passportMapper.getUserDetails(l);
        MyUserDetails myUserDetails = new MyUserDetails();
        BeanUtils.copyProperties(userDetails,myUserDetails);
        return myUserDetails ;
    }
}
